import struct

def printgraph():
    totalnode = 0
    binfile = open('db.webgraph','rb')
    intsize = struct.calcsize('i')

    while 1:
        data = binfile.read(intsize)
        if data == '':
            break
        src = struct.unpack('i',data)[0]
        print '>',src,
        totalnode += 1

        data = binfile.read(intsize)
        if data == '':
            break
        outdegree = struct.unpack('i',data)[0]
        print outdegree,
        
        for i in range(outdegree[0]):
            data = binfile.read(intsize)
            if data == '':
                break
            dest = struct.unpack('i',data)[0]
            print dest,
        print ''
    print 'totalnode = ',totalnode
    binfile.close()

if __name__ == "__main__":
    printgraph()
